package com.shangyitong.yygh_order.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shangyitong.Result;
import com.shangyitong.yygh.enums.OrderStatusEnum;
import com.shangyitong.yygh.model.order.OrderInfo;
import com.shangyitong.yygh.vo.order.OrderCountQueryVo;
import com.shangyitong.yygh.vo.order.OrderQueryVo;
import com.shangyitong.yygh_order.service.OrderService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;

@RestController
@Slf4j
@RequestMapping("/api/order/orderInfo")
public class OrderController {
    @Autowired
    private OrderService orderService;
    /**
     * 确认挂号
     * finished
     * @param scheduleId
     * @param patientId
     * @return
     */
    @ApiOperation(value = "确认挂号")
    @PostMapping("/auth/submitOrder/{scheduleId}/{patientId}")
    public Result submitOrder(@PathVariable String scheduleId,
                              @PathVariable Long patientId) {
        Long orderId = orderService.saveOrder(scheduleId, patientId);
        return Result.ok(orderId);
    }

    /**
     * 订单列表
     * finished
     * @param page
     * @param limit
     * @param orderQueryVo
     * @param request
     * @return
     */
    @ApiOperation(value = "订单列表")
    @GetMapping("/auth/{page}/{limit}")
    public Result getOrders(@PathVariable Integer page,
                            @PathVariable Integer limit,
                            OrderQueryVo orderQueryVo,
                            HttpServletRequest request) {
        Page<OrderInfo> orderList = orderService.getOrders(page, limit, orderQueryVo, request);
        return Result.ok(orderList);
    }

    /**
     * 获取订单状态
     * finished
     * @return
     */
    @ApiOperation(value = "获取订单状态")
    @GetMapping("/auth/getStatusList")
    public Result getStatusList() {
        List<Map<String, Object>> statusList = OrderStatusEnum.getStatusList();
        return Result.ok(statusList);
    }

    /**
     * 订单详细
     * finished
     * @param orderId
     * @return
     */
    @ApiOperation(value = "订单详细")
    @GetMapping("/auth/getOrders/{orderId}")
    public Result getOrderDetails(@PathVariable Long orderId) {
        OrderInfo orderInfo = orderService.getById(orderId);
        orderInfo.getParam().put("orderStatusString", OrderStatusEnum.getStatusNameByStatus(orderInfo.getOrderStatus()));
        return Result.ok(orderInfo);
    }
    /**
     * 取消预约
     * finished
     * @param orderId
     * @return
     */
    @ApiOperation(value = "取消预约")
    @GetMapping("/auth/cancelOrder/{orderId}")
    public Result cancelOrder(@PathVariable Long orderId) {
        boolean isOrder = orderService.cancelOrder(orderId);
        return Result.ok(isOrder);
    }

    /**
     * 获取订单数据
     * x轴 y轴
     * finished
     * @param orderCountQueryVo
     * @return
     */
    @ApiOperation(value = "获取订单数据")
    @PostMapping("inner/getCountMap")
    public Map<String,Object> getCountMap(@RequestBody OrderCountQueryVo orderCountQueryVo){
        return orderService.getCountMap(orderCountQueryVo);
    }
}

